package com.liu.fresh.biz.impl;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.liu.fresh.biz.IGoodsInfoBiz;
import com.liu.fresh.entity.GoodsInfo;
import com.liu.fresh.mapper.IGoodsInfoMapper;
import com.liu.fresh.util.StringUtil;

@Service
public class GoodsInfoBizImpl implements IGoodsInfoBiz{
	@Autowired
	private IGoodsInfoMapper mapper;

	@Override
	public List<GoodsInfo> findAll() {
		return mapper.findAll();
	}

	@Override
	public GoodsInfo find(String str) {
		if(StringUtil.checkNull(str)){
			return null;
		}
		Map<String, String> map = new HashMap<String, String>();
		map.put("str", str);
		return mapper.find(map);
	}

	@Override
	public List<GoodsInfo> findByTno(String tno, String start) {
		if(StringUtil.checkNull(tno,start)){
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("tno", tno);
		map.put("start", start);
		return mapper.findByTno(map);
	}

	@Override
	public Integer updateBal(String[] gnos, String[] nums) {
		if(StringUtil.checkNull(gnos,nums)){
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		int result=0;
		for(int i=0;i<gnos.length;i++){
			map.put("gno", gnos[i]);
			map.put("num", nums[i]);
			result+=mapper.updateBal(map);
		}
		return result;
		
	}

	@Override
	public List<GoodsInfo> finds() {
		return mapper.finds();
	}

	//添加商品
	@Override
	public int addGood(Map<String, Object> map) {
		if(StringUtil.checkNull(map.get("gname"),map.get("tno"),map.get("intro"))){
			return -3;
		}
		return mapper.addGood(map);
	}

	@Override
	public List<GoodsInfo> findgoods() {
		return mapper.findgoods();
	}

	@Override
	public int del(String gno) {
		if(StringUtil.checkNull(gno)){
			return 0;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("gno", gno);
		return mapper.del(map);
	}

	@Override
	public int getTotal(String tno) {
		if(StringUtil.checkNull(tno)){
			return 0;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("tno", tno);
		return mapper.getTotal(map);
	}
		
}
